<template>
	<view class="page">
		<view>
			<swiper :indicator-dots="false" :autoplay="false" :interval="3000" :duration="200" :circular="false" style="width: 100%;height: 750upx;">
				<swiper-item v-for="(item,index) in imgList" :key="index" style="width: 100%;height: 750upx;">
					<image style="width: 100%;height: 750upx;" :src="item" mode="aspectFill" @tap="previewImg(index)"></image>
				</swiper-item>
				
			</swiper>
			<!-- <view v-for="(item,index) in imgList" :key="index" >
				<image style="width: 100%;height: 750upx;" :src="item" mode="widthFix" @tap="previewImg(index)"></image>
			</view> -->
			
			<view style="display: flex;flex-direction: row;justify-content: space-between;
			padding: 20upx 30upx;align-items: center;">
				<view style="display: flex;flex-direction: row;align-items: center;"><span style="color: #FF4E4C;font-size: 24upx;font-weight: bold;">￥</span>
				 <span style="color: #FF4E4C;font-size: 48upx;font-weight: bold;">{{sourceDetail.price}}</span>
				 </view>
				<view style="height: 40upx;border: 1upx solid #FFD5AB;border-radius: 8upx;
				line-height: 40upx; text-align: center;color: #FF9428 ;font-size: 24upx;
				padding-left: 12upx;padding-right: 12upx;">{{sourceDetail.techTypeName}}</view>
			</view>
			<view style="color: #191919;font-size: 30upx;font-weight: bold;margin-left: 30upx;">{{sourceDetail.title}}</view>
			<view style="color: #191919;font-size: 26upx;margin-left: 30upx;margin-right: 30upx;margin-top: 32upx;">
				{{sourceDetail.description}}
			</view>
		</view>
		
		
		<view style="position: fixed;bottom: 0upx;height: 96upx;width: 100%;margin-bottom: 68upx;display: flex;
		flex-direction: row;justify-content: space-between;align-items: center;">
			<view style="display: flex;flex-direction: row;">
		
			<button
				style="display: flex;flex-direction: column;margin-right: 24upx;justify-content: center;background-color:transparent !important;border: none !important;outline: none !important;"
				@click="shareDemand" open-type="share">
				<image style="width: 48upx;height: 48upx;" src="../../static/images/share-icon.png" mode=""></image>
			
			</button>
				
			</view>
			
			<view style="background: #FF4E4C;color: #FFFFFF;font-size: 28upx;
			height: 72upx;width: 268upx;line-height: 72upx;text-align: center;
			border-radius: 48upx;margin-right: 60upx;" @click='copy("复制微信 18483678377 添加好友购买")'>
				联系客服
			</view>
			
			
		</view>
		
		
	</view>
</template>

<script>
		import{source_code_detail,update_view_count} from '../../api/source-code/source-code.js'
	export default {
		data() {
			return {
				sourceDetail:{},
				imgList:[],
				detailId:""
			}
		},
		onShow() {
			this.updateViewCount()
		},
		onLoad(options) {
			this.getSourceCodeDetail(options.id)
			this.detailId=options.id
		},
		methods: {
			copy(val){
				//提示模板
				  uni.showModal({
				    content:val,//模板中提示的内容
				    confirmText:'复制内容',
				    success:(res)=>{//点击复制内容的后调函数
						if(res.confirm){
							//uni.setClipboardData方法就是讲内容复制到粘贴板
							uni.setClipboardData({
							  data:val,//要被复制的内容
							  success:()=>{//复制成功的回调函数
							    uni.showToast({//提示
								  icon:'none',
							      title:'已复制到剪切板'
							    })
							  }
							});
						}else{
							
						}
				      
				    }
				  });
			},
			previewImg(index) {
				console.log("index:"+index)
				let _this = this;
				let imgsArray = [];
				for (let i = 0; i < this.imgList.length; i++) {
						imgsArray.push(this.imgList[i]);
					
				}
				uni.previewImage({
					current: index,
					urls: imgsArray,
					indicator: 'number',
					loop: true,
					longPressActions:{
						itemList:['保存图片'],
						success(res) {
							console.log(res)
							uni.downloadFile({
								url:this.imgList[index],
								success(result) {
									uni.saveImageToPhotosAlbum({
										filePath:result.tempFilePath,
										success() {
											uni.showToast({
												title:'保存成功'
											})
										}
									})
								}
							})
						}
					}
				});
			},
			
			
			updateViewCount() {
				let params = {}
				params.id = this.detailId;
				update_view_count(params).then(res => {
			
				})
			},
			getSourceCodeDetail(id){
				let params={}
				params.id=id
				source_code_detail(params).then(res=>{
					this.sourceDetail=res.data
					this.imgList=res.data.images
				})
			},
			shareDemand() {
				uni.share({
					provider: "weixin",
					scene: "WXSceneSession",
					type: 0,
					href: "http://uniapp.dcloud.io/",
					title: this.sourceDetail.title,
					summary: this.sourceDetail.description,
					imageUrl: this.sourceDetail.images[0],
					success: function(res) {
						console.log("success:" + JSON.stringify(res));
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
					}
				})
			},
		}
	}
</script>

<style>
.page{
	background: #FFFFFF;
}

button::after {
		border: none;
	}
</style>
